package shuishijie.suishijie.model;

import android.text.TextUtils;



import java.util.Calendar;
import java.util.List;

import shuishijie.suishijie.util.AppUtil;

/**
 * Created by mindx on 2017/8/29.
 */

public class HotTimeInfo {

    /**
     * child : [{"beginTime":"2017-08-31 17:55:14","status":0,"timeActivity_id":119},{"beginTime":"2017-09-06 09:00:00","status":2,"timeActivity_id":120}]
     * nowTime : 2017-09-08 22:12:34
     */

    public String nowTime;
    public List<timeInfo> child;

    public static class timeInfo {
        /**
         * beginTime : 2017-08-31 17:55:14
         * status : 0
         * timeActivity_id : 119
         */

        public String beginTime;
        public String endTime;
        public int status;
        public int timeActivity_id;


        public String getTime() {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(AppUtil.parserDate(beginTime));
            String str = String.format("%02d:%02d", calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE));
            return str;
        }


        public String firstOfDay(String last) {
            String ret = null;
            Calendar currentTime = Calendar.getInstance();
            currentTime.setTime(AppUtil.parserDate(beginTime));
            Calendar lastTime = Calendar.getInstance();

            int date = currentTime.get(Calendar.DATE);
            if (!TextUtils.isEmpty(last)) {
                lastTime.setTime(AppUtil.parserDate(last));
            } else {
                lastTime.set(Calendar.DATE, date - 1);
            }
            if (date != lastTime.get(Calendar.DATE)) {
                Calendar tmpDate = Calendar.getInstance();
                int today = tmpDate.get(Calendar.DATE);

                tmpDate.add(Calendar.DATE, -1);
                int yesterday = tmpDate.get(Calendar.DATE);

                tmpDate.add(Calendar.DATE, 2);
                int tomorrow = tmpDate.get(Calendar.DATE);
                if (date == today) {
                    ret = "今天";
                } else if (date == yesterday) {
                    ret = "昨天";
                } else if (date == tomorrow) {
                    ret = "明天";
                } else {
                    ret = String.format("%02d-%02d", currentTime.get(Calendar.MONTH) + 1, currentTime.get(Calendar.DATE));
                }
                //ret += "\n" + GloblaData.getHotTimeStatus(beginTime, endTime, status);
            }
            return ret;
        }
    }
}
